const { obd_collection } = require('../config')
const { staff_collection } = require('../config')
const { grid_collection } = require('../config')
const { db } = require('../config')
const { command } = require('../config')
const _ = command
// 返回
exports.main = async (event, context) => {
    const data = event;
    filter = {};
    data.staffName && (filter.name = new RegExp(data.staffName, 'i'))
    data.staff && (filter.staff = new RegExp(data.staff, 'i'))
    if (!(filter.hasOwnProperty('staff') || filter.hasOwnProperty('name'))) {
        return { code: 0, msg: "请输入员工账号或者姓名" }
    }
    const staffInfo = await db.collection(staff_collection).where(filter).limit(1).get();
    const staffData = staffInfo.data[0];
    const gridInfo = await db.collection(grid_collection).where({ grid: staffData.grid }).get();
    const gridCenter = gridInfo.data[0].center;
    const centersDistance = gridInfo.data[0].centersDistance;
    // return staffData;
    if (staffData.obdLongLat) {
        return { 'lineLongLat': staffData.lineLongLat, 'allObdLongLat': staffData.obdLongLat, 'userCount': staffData.userCount, 'allObdCount': staffData.obdLongLat.length, 'perimeter': staffData.perimeter, 'area': staffData.area, 'center': staffData.center, 'region': staffData.region, 'grid': staffData.grid, 'gridCenter': gridCenter, 'centersDistance': centersDistance }
    } else {
        return { 'msg': '该员工没有负责的OBD' }
    }
}